﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContactUC.ascx.cs" Inherits="ERP.PageUC.ContactUC" %>
<%@ Register Src="~/PageUC/JobUC.ascx" TagPrefix="uc1" TagName="JobUC" %>
<%@ Register Src="~/PageUC/VocativeUC.ascx" TagPrefix="uc1" TagName="VocativeUC" %>
<%@ Register Src="~/PageUC/DepartmentUC.ascx" TagPrefix="uc1" TagName="DepartmentUC" %>
<%@ Register Src="~/PageUC/DistrictsUC.ascx" TagPrefix="uc1" TagName="DistrictsUC" %>

<script>
    $(document).ready(function () {
        PopupUpdate('#lienhe_themchucvu');
        PopupUpdate('#lienhe_themdanhxung');
        PopupUpdate('#lienhe_themphongban');
        PopupUpdate('#lienhe_themquanhuyen');
    });
</script>
<script>
    function CheckSaveContact() {
        var emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
        var kt1 = $('#<%=txtMaDoiTuong.ClientID %>');
        var kt2 = $('#<%=txtHoVaTen.ClientID %>');
        var kt3 = $('#<%=txtEmail.ClientID %>');
        var allFields = $([]).add(kt1).add(kt2).add(kt3);
        var valid;
        allFields.removeClass("ui-state-error");
        valid = checkLength(kt1, "Mã đối tượng", 1, 50);
        valid = valid && checkLength(kt2, "Họ và tên", 1, 50);
        valid = valid && checkRegexp(kt3, emailRegex, "Email không đúng. Ví dụ:abc@com.vn");
        if (valid) {
            updateTips('');
            allFields.removeClass("ui-state-error");
        }
        return valid;
    }
</script>
<script>
    function setSelectedValue(selectObj, valueToSet) {
        for (var i = 0; i < selectObj.options.length; i++) {
            if (selectObj.options[i].text == valueToSet) {
                selectObj.options[i].selected = true;
                return;
            }
        }
    }
    function DetailRowsDirect(x) {
        //gets table
        var getTable = document.getElementById('MyTableContact');
        //gets cells of current row  
        var getCells = getTable.rows.item(x.rowIndex).cells;

        document.getElementById('<%=lbID.ClientID %>').value = getCells.item(0).innerHTML;
            document.getElementById('<%=txtMaDoiTuong.ClientID %>').disabled = true;
            document.getElementById('<%=txtMaDoiTuong.ClientID %>').value = getCells.item(2).innerHTML;
            document.getElementById('<%=txtHoVaTen.ClientID %>').value = getCells.item(1).innerHTML;
            document.getElementById('<%=txtNgaySinh.ClientID %>').value = getCells.item(3).innerHTML;
            setSelectedValue(document.getElementById('<%=drGioiTinh.ClientID %>'), getCells.item(4).innerHTML);
            setSelectedValue(document.getElementById('<%=drChucVu.ClientID %>'), getCells.item(5).innerHTML);
            setSelectedValue(document.getElementById('<%=drDanhXung.ClientID %>'), getCells.item(6).innerHTML);
            setSelectedValue(document.getElementById('<%=drPhongBan.ClientID %>'), getCells.item(7).innerHTML);
            document.getElementById('<%=txtDienThoai.ClientID %>').value = getCells.item(8).innerHTML;
            document.getElementById('<%=txtDiDong.ClientID %>').value = getCells.item(9).innerHTML;
            document.getElementById('<%=txtEmail.ClientID %>').value = getCells.item(10).innerHTML;
            document.getElementById('<%=txtDiaChi.ClientID %>').value = getCells.item(11).innerHTML;
            setSelectedValue(document.getElementById('<%=drTinh.ClientID %>'), getCells.item(12).innerHTML);
            setSelectedValue(document.getElementById('<%=drQuanHuyen.ClientID %>'), getCells.item(13).innerHTML);
        }
    </script>
<asp:UpdatePanel ID="upNewUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server">
    <ContentTemplate>
        <table>
            <td>
                <div class="ui-main" style="height: 308px; overflow: auto;">
                    <asp:ListView ID="ListViewContact" runat="server" DataKeyNames="Contact_ID">
                        <LayoutTemplate>
                            <table id="MyTableContact" class="tablesorter">
                                <thead>
                                    <tr>
                                        <th style="text-align: center" data-sorter="false" data-filter="false">STT</th>
                                        <th style="text-align: center">Họ và tên</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr id="itemPlaceholder" runat="server">
                                    </tr>
                                </tbody>
                            </table>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr runat="server" onclick="DetailRowsDirect(this)" class="warning">
                                <td><%# Eval("Contact_ID") %></td>
                                <td><%# Eval("Contact_Name") %></td>
                                <td style="display: none"><%# Eval("Contact_Alias") %></td>
                                <td style="display: none"><%# Eval("Contact_BirthDay","{0:dd/MM/yyyy}") %></td>
                                <td style="display: none"><%# Eval("Contact_Gender") %></td>
                                <td style="display: none"><%# Eval("Job_Name") %></td>
                                <td style="display: none"><%# Eval("Vocative_Name") %></td>
                                <td style="display: none"><%# Eval("Department_Name") %></td>
                                <td style="display: none"><%# Eval("Contact_Phone") %></td>
                                <td style="display: none"><%# Eval("Contact_MobilePhone") %></td>
                                <td style="display: none"><%# Eval("Contact_Email") %></td>
                                <td style="display: none"><%# Eval("Contact_Address") %></td>
                                <td style="display: none"><%# Eval("Province_Name") %></td>
                                <td style="display: none"><%# Eval("Districts_Name") %></td>
                            </tr>
                        </ItemTemplate>
                        <EmptyDataTemplate>
                            <div class='alert alert-danger'>
                                <a href='#' class='close' data-dismiss='alert'>&times;</a>
                                Không tìm thấy mẫu tin nào !
                            </div>

                        </EmptyDataTemplate>
                    </asp:ListView>
                </div>
            </td>
            <td>

                <div class="ui-main" style="width: 608px;">
                    <div class="btn-toolbar">
                        <asp:Button ID="btnSavePopup" CssClass="btn-save btn-default" title="Lưu lại" runat="server" OnClientClick="return CheckSaveContact();" OnClick="btnSavePopup_Click" />
                        &nbsp;
            <asp:Button ID="btnReloadPopup" CssClass="btn-reload btn-default" title="Tải lại" runat="server" OnClick="btnReloadPopup_Click" />
                        &nbsp;
            <input type="hidden" id="lbID" runat="server" /><label class="validateTips"></label>
                        <asp:UpdateProgress ID="upDateProcessUC" runat="server" AssociatedUpdatePanelID="upNewUpdatePanel">
                            <ProgressTemplate>
                                <span class="label label-warning">Đang tải..</span>
                            </ProgressTemplate>
                        </asp:UpdateProgress>
                    </div>
                    <div class="ui-box">
                        <label class="labelpopupnew">Mã đối tượng :</label>
                        <asp:TextBox ID="txtMaDoiTuong" CssClass="textbox_child_text" runat="server" data-allow="add"></asp:TextBox>
                    </div>
                    <div class="clr"></div>
                    <div class="ui-box">
                        <label class="labelpopupnew">Họ và tên :</label>
                        <asp:TextBox ID="txtHoVaTen" Style="width: 480px;" CssClass="textbox_child_text" runat="server"></asp:TextBox>
                    </div>
                    <div class="ui-box">
                        <label class="labelpopupnew">Ngày Sinh :</label>
                        <asp:TextBox ID="txtNgaySinh" CssClass="textbox_child_text_ngay" runat="server"></asp:TextBox>
                        &nbsp;
                <label class="labelpopup" style="width: 85px;">Giới tính :</label>
                        <asp:DropDownList ID="drGioiTinh" CssClass="textbox_child_text" runat="server">
                            <asp:ListItem></asp:ListItem>
                            <asp:ListItem>Nam</asp:ListItem>
                            <asp:ListItem>Nữ</asp:ListItem>
                        </asp:DropDownList>
                    </div>
                    <div class="ui-box">
                        <label class="labelpopupnew">Chức vụ :</label>
                        <asp:DropDownList ID="drChucVu" AppendDataBoundItems="true" CssClass="textbox_child_text_drop" runat="server"></asp:DropDownList>
                        <a class="relationlink" onclick="return Show('#lienhe_themchucvu');">...</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                <label class="labelpopup">Danh xưng :&nbsp;&nbsp;</label>
                        <asp:DropDownList ID="drDanhXung" AppendDataBoundItems="True" CssClass="textbox_child_text_drop" runat="server"></asp:DropDownList>
                        <a class="relationlink" onclick="return Show('#lienhe_themdanhxung');">...</a>
                    </div>
                    <div class="ui-box">
                        <label class="labelpopupnew">Phòng Ban :</label>
                        <asp:DropDownList ID="drPhongBan" AppendDataBoundItems="true" CssClass="textbox_child_text_drop" runat="server"></asp:DropDownList>
                        <a class="relationlink" onclick="return Show('#lienhe_themphongban');">...</a>
                    </div>
                    <div class="clr"></div>
                    <div class="ui-box">
                        <label class="labelpopupnew">Điện Thoại :</label>
                        <asp:TextBox ID="txtDienThoai" onkeydown="javascript:backspacerDOWN(this,event);" onkeyup="javascript:backspacerUP(this,event);" CssClass="textbox_child_text" runat="server"></asp:TextBox>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                <label class="labelpopup" style="width: 86px">Di Động :</label>
                        <asp:TextBox ID="txtDiDong" onkeydown="javascript:backspacerDOWN(this,event);" onkeyup="javascript:backspacerUP(this,event);" CssClass="textbox_child_text" runat="server"></asp:TextBox>
                    </div>
                    <div class="ui-box">
                        <label class="labelpopupnew">Email :</label>
                        <asp:TextBox ID="txtEmail" Style="width: 480px;" CssClass="textbox_child_text" runat="server"></asp:TextBox>
                    </div>
                    <div class="ui-box">
                        <label class="labelpopupnew">Địa chỉ :</label>
                        <asp:TextBox ID="txtDiaChi" Style="width: 480px;" CssClass="textbox_child_text" runat="server"></asp:TextBox>
                    </div>
                    <div class="ui-box">
                        <label class="labelpopupnew">Tỉnh :</label>
                        <asp:DropDownList ID="drTinh" AppendDataBoundItems="True" AutoPostBack="True" CssClass="textbox_child_text_drop" runat="server" OnSelectedIndexChanged="drTinh_SelectedIndexChanged"></asp:DropDownList>
                        <a class="relationlink" onclick="return Show('#quanhuyen_themtinh');">...</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                <label class="labelpopup">Quận Huyện :</label>
                        <asp:DropDownList ID="drQuanHuyen" Enabled="False" AppendDataBoundItems="True" CssClass="textbox_child_text_drop" runat="server"></asp:DropDownList>
                        <a class="relationlink" onclick="return Show('#lienhe_themquanhuyen');">...</a>
                    </div>
                </div>
            </td>
        </table>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSavePopup" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
<div id="lienhe_themchucvu" title="Cập nhật chức vụ">
    <uc1:JobUC runat="server" ID="JobUC" />
</div>
<div id="lienhe_themdanhxung" title="Cập nhật danh xưng">
    <uc1:VocativeUC runat="server" ID="VocativeUC" />
</div>
<div id="lienhe_themphongban" title="Cập nhật phòng ban">
    <uc1:DepartmentUC runat="server" ID="DepartmentUC" />
</div>
<div id="lienhe_themquanhuyen" title="Cập nhật quận huyện">
    <uc1:DistrictsUC runat="server" ID="DistrictsUC" />
</div>

